var _tabelHot = {
  getData: null,
  getLastSelect: null,
  instance: null,
  loadData: function () {
    var _this = this
    $.getJSON("./json/data.json",
      function (data, textStatus, jqXHR) {
        // var ajaxdata = JSON.parse(data);
        var ajaxdata = data;
        _this.getData = ajaxdata;
        _this.instance.loadData(ajaxdata)
      }
    );
  }
}
$(function () {
  // 创建变量
  $("#tabel").handsontable({
    startRows: 30,//初始行数
    startCols: 30,//初始列数
    // width: $('body').width(),
    minRows: 30,
    minCols: 30,
    minSpareCols: 2,//多出空白列
    minSpareRows: 2,//多出空白行
    colHeaders: true, //显示列头
    rowHeaders: true, //显示行头
    contextMenu: true, //显示表头下拉菜单,
    manualColumnResize: true,//允许拖曳列表头
    manualRowResize: true, //允许拖曳行表头,
    afterSelectionEndByProp: function () {
      var x = arguments;
      _tabelHot.getLastSelect = [x[0], x[1], x[2] - x[0], x[3] - x[1]]
    },
    cell: [
      {
        data: 1,
        // renderer: function (instance, td, row, col, prop, value, cellProperties) { console.log(params); }
      }],
    afterChange: function (data, name, z) {
      // name编辑类型
      // data :[x-1,y-1,newVal,oldVal]
      switch (name) {
        case 'edit':
          console.log('编辑');
          break;
        case 'loadData':
          console.log('加载');
          break;
        case 'Autofill.fill':
          console.log('格式刷');
          break;
        case 'CopyPaste.paste':
          console.log('粘贴');
          break;
        case 'UndoRedo.undo':
          console.log('撤销');
          break; case 'UndoRedo.redo':
          console.log('重做');
          break;
        default:
          console.log('其他');
          console.log(name);
          console.log(data);
          break;
      }
    }
  });
  _tabelHot.instance = $("#tabel").handsontable('getInstance');
  _tabelHot.loadData();
});
function xxx() {
  var _this = _tabelHot.instance;

  console.log(_tabelHot.instance);
}